﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jbe.TestSuite.TestDevices.FunctionGenerator.Driver.Domain
{
    internal static class WaveFormStrategies
    {
        public static double Sine(double amplitude, double frequency, double time)
        {
            return amplitude * Math.Sin(2 * Math.PI * frequency * time);
        }

        public static double Square(double amplitude, double frequency, double time)
        {
            double normalizedTime = time - Math.Floor(time * frequency) / frequency;
            normalizedTime = (2 * normalizedTime * frequency) - 1;

            return (normalizedTime >= 0) ? -amplitude : amplitude;
        }

        public static double Triangle(double amplitude, double frequency, double time)
        {
            time -= 0.25 / frequency;
            double normalizedTime = time - Math.Floor(time * frequency) / frequency;
            normalizedTime = (2 * normalizedTime * frequency) - 1;

            return 2 * amplitude * Math.Sign(normalizedTime) * normalizedTime - amplitude;
        }

        public static double Sawtooth(double amplitude, double frequency, double time)
        {
            time -= 0.5 / frequency;
            double normalizedTime = time - Math.Floor(time * frequency) / frequency;
            normalizedTime = normalizedTime * frequency;

            return 2 * amplitude * normalizedTime - amplitude;
        }
    }
}
